package day05;

import day02.Order.User;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/24
 */
//浅拷贝
public class ObjectDemo {
    public static void main(String[] args) throws CloneNotSupportedException {
        double[] scores={90.0,87.5,78,100,99.0};
        Person p1 = new Person("小明",16,scores);
        Person p2 = (Person) p1.clone();
        double[] scores2=p1.getScores();
        scores2[0]=100;
        System.out.println(p1);
        System.out.println(p2);
    }
}
class Person implements Cloneable{
    private String name;
    private int age;
    double[] scores;
    public Person() {
    }

    public Person(String name, int age, double[] scores) {
        this.name = name;
        this.age = age;
        this.scores = scores;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return scores
     */
    public double[] getScores() {
        return scores;
    }

    /**
     * 设置
     * @param scores
     */
    public void setScores(double[] scores) {
        this.scores = scores;
    }

    public StringBuilder scoreTostring(double[] scores){
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < scores.length; i++) {
            sb.append(scores[i]);
            if(i!=scores.length-1){
                sb.append(",");
            }
        }
        sb.append("]");
        return sb;
    }
    public String toString() {
        String s;
        return "Person{name = " + name + ", age = " + age + ", scores = " + scoreTostring(scores)+ "}";
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

}
